home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MACD 5
/
MACD 5.bin
/
workbench
/
boot
/
czesc_2
/
sandglass
/
sandglass_sources.lzh
/
SandGlass.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-06
|
8KB
|
310 lines
/* ========================================================================== */
/* SandGlass V1.0 by Dirk O. Remmelt */
/* -------------------------------------------------------------------------- */
/* This program animates the Workbench-busy-or-zz-mouse-pointer. After */
/* starting the program, and while a disk-device-access is taking place, the */
/* mouse-pointer represents itself as a sandglass, purling sand through it, */
/* turning around and starting all over again. ( A rather long sentence, */
/* Douglas N. Adams would be proud of me! ) */
/* Please read also the SandGlass.doc file ! */
/* ========================================================================== */
#include <exec/exec.h> /* includes */
#include <graphics/gfx.h>
#include <graphics/gfxbase.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <workbench/startup.h>
#include <workbench/icon.h>
#include <workbench/workbench.h>
#include <stdio.h>
#include "ImageDatas.h"
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct IconBase *IconBase;
struct Task *ThisTask;
struct IntuiMessage *IntuiMsg;
struct Screen *WBScreen; /* ptr to Workbench-Screen */
struct Window *SandGlassWindow = NULL, /* window to quit SandGlas */
*ActiveWindow;
struct NewWindow nw = /* window-declaration of */
{ /* SandGlasWindow */
0, 11, /* LeftEdge, TopEdge */
103, 10, /* Width, Height */
0, 1, /* DetailPen, BlockPen */
CLOSEWINDOW, /* IDCMPFlags */
WINDOWCLOSE | NOCAREREFRESH, /* Flags */
NULL, NULL, /* FirstGadget, CheckMark */
(UBYTE *) "SandGlass", /* Title */
NULL, NULL, /* Screen, BitMap */
103, 10, /* MinWidth, MinHeight */
103, 10, /* MaxWidth, MaxHeight */
WBENCHSCREEN /* Type */
};
USHORT *pointer; /* start-address of and */
USHORT old_pointer [48]; /* buffer for original zz- */
/* mouse-pointer */
int delay = 5,
priority = -10,
old_priority;
extern void CloseGraphix ();
void SetMyPointer ( int number ) /* procedure to set one of */
{ /* the 14 images */
int i;
for ( i=0; i<32; i++ )
*(pointer+i+16) = ImageData [number][i];
return ();
}
void OpenGraphix ()
{
int i;
if ( ! ( GfxBase = (struct GfxBase *)
OpenLibrary ( "graphics.library", 0L ) ) )
{
printf ( "Can't open graphics.library !\n" );
CloseGraphix ();
}
if ( ! ( IntuitionBase = (struct IntuitionBase *)
OpenLibrary ( "intuition.library", 0L ) ) )
{
printf ( "Can't open intuition.library !\n" );
CloseGraphix ();
}
if ( ! ( SandGlassWindow = (struct Window *)
OpenWindow ( &nw ) ) )
{
printf ( "Can't open window !\n" );
CloseGraphix ();
}
ThisTask = FindTask ( NULL );
if ( ThisTask ) old_priority = SetTaskPri ( ThisTask, priority );
WBScreen = IntuitionBase->FirstScreen;
return ();
}
int compare ( char *str_ptr_1, char *str_ptr_2, int length )
{
APTR ptr;
if ( ! ( strncmp ( str_ptr_1, str_ptr_2, length ) ) )
{
if ( ( strlen ( str_ptr_2 ) ) > length )
{
ptr = (APTR)( (int)str_ptr_2 + (int)length );
return ( atoi ( ptr ) );
}
}
return ( -1 );
}
void GetSetups ( int count, char *arg_ptr [], struct WBStartup *arg_wb_ptr )
{
int i, x;
struct WB_Arg *wb_args;
struct DiskObject *disk_obj;
char **toolarray;
char *s;
if ( count ) /* started from CLI */
{
for ( i=1; i<count; i++ )
*arg_ptr [i] = (char)( toupper ( (int)(*arg_ptr [i]) ) );
for ( i=1; i<count; i++ )
{
if ( ! strcmp ( arg_ptr [i], "?" ) )
{
printf ( "Usage: SandGlass [?] [D=delay] [P=priority]\n" );
exit ( 0 );
}
else
if ( ( ( x = compare ( "D=", arg_ptr [i], 2 ) ) != -1 ) )
{
if ( x < 0 )
{
printf ( "Process Delay Time must be 0<=delay!\n" );
exit ( 0 );
}
else delay = x;
}
else
if ( ( ( x = compare ( "P=", arg_ptr [i], 2 ) ) != -1 ) )
{
if ( ( x < -128 ) || ( x > 127 ) )
{
printf ( "Task Priority must be -128<=priority<=127!\n" );
exit ( 0 );
}
else priority = x;
}
}
}
else /* started from Workbench */
{
if ( IconBase = ( struct IconBase *)
OpenLibrary ( "icon.library", 0L ) )
{
wb_args = (struct WBArg *)arg_wb_ptr->sm_ArgList;
if ( *wb_args->wa_Name )
{
if ( disk_obj = GetDiskObject ( wb_args->wa_Name ) )
{
toolarray = (char **)disk_obj->do_ToolTypes;
if ( s = (char *)FindToolType ( toolarray, "DELAY" ) )
{
delay = atoi ( s );
if ( delay < 0 ) delay = 5;
}
if ( s = (char *)FindToolType ( toolarray, "PRIORITY" ) )
{
priority = atoi ( s );
if ( ( priority < -128 ) || ( priority > 127 ) ) priority = -10;
}
FreeDiskObject ( disk_obj );
}
}
CloseLibrary ( IconBase );
}
}
return ();
}
void ActOnIDCMP ()
{
ULONG class;
if ( IntuiMsg = (struct IntuiMessage *) /* check for window-close- */
GetMsg ( SandGlassWindow->UserPort ) ) /* message */
{
class = IntuiMsg->Class;
ReplyMsg ( IntuiMsg );
if ( class == CLOSEWINDOW ) CloseGraphix ();
}
return ();
}
void CloseGraphix ()
{
int i;
if ( pointer )
for ( i=0; i<48; i++ ) /* restore original mouse- */
*(pointer+i) = old_pointer [i]; /* pointer */
SetTaskPri ( ThisTask, old_priority );
if ( SandGlassWindow ) CloseWindow ( SandGlassWindow );
if ( GfxBase ) CloseLibrary ( GfxBase );
if ( IntuitionBase ) CloseLibrary ( IntuitionBase );
exit ( 0 );
}
void main ( int argc, char *argv[] )
{
int i;
GetSetups ( argc, argv, argv );
OpenGraphix ();
ActiveWindow = IntuitionBase->ActiveWindow;
while ( ( ! ActiveWindow->Pointer ) ||
( ActiveWindow->WScreen != WBScreen ) )
{
ActOnIDCMP ();
ActiveWindow = IntuitionBase->ActiveWindow;
Delay ( delay );
}
pointer = ActiveWindow->Pointer;
for ( i=0; i<48; i++ ) /* save original mouse- */
old_pointer [i] = *(pointer+i); /* pointer */
for ( i=0; i<16; i++ ) /* clear first 8 rows */
*(pointer+i) = 0x0000;
SetMyPointer ( 0 ); /* set first image */
for (;;)
{
ActOnIDCMP ();
for ( i=0; i<14; i++ )
{
ActiveWindow = IntuitionBase->ActiveWindow;
if ( ( ActiveWindow->Pointer ) && ( ActiveWindow->WScreen == WBScreen ) )
SetMyPointer ( i ); /* animate only Workbench- */
/* zz-mouse-pointer */
Delay ( delay );
}
}
}